home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Game Master (3rd Edition)
/
The Game Master 3rd edition.iso
/
files
/
windonal
/
fuzzgen
/
testbool.c
< prev
next >
Wrap
Text File
|
1992-08-05
|
4KB
|
196 lines
/* This code was produced by FUZZGEN, the Fuzzy */
/* Logic Code Generator from Alston Software Labs. */
/* The following is the GLOBAL variable list: */
#define d1l 0
#define d1r 40
#define apex1l 0
#define apex1r 10
#define d2l 10
#define d2r 90
#define apex2 50
#define d3l 60
#define d3r 100
#define apex3l 80
#define apex3r 100
#define d4l 35.77
#define d4r 67.543
/*
Functions that use these variables follow.
Functions are NUMBERED and use the SAME NUMBER
variables. For instance, Function DECISION1 uses
apexl1, apexr1, etc...
*/
double Decision1( double testdata, double blo,
double bhi, double ap1, double ap2 )
{
double Membership, baseL, baseR, ratioL, ratioR;
/* Exit if data not in bounds... */
if (testdata < blo) return 0;
if (testdata > bhi) return 0;
/* Data is within set boundry... */
baseL = ap1 - blo;
baseR = bhi - ap1;
ratioL = 0;
ratioR = 0;
/* Normalise test data */
if (baseL > 0) ratioL = 100 / baseL;
if (baseR > 0) ratioR = 100 / baseR;
/* TRAPEZOIDAL */
if((testdata >= ap1) && (testdata <= ap2))
Membership = 100.0;
if(testdata <= ap1)
Membership = (testdata - baseL) * ratioL;
if(testdata > ap2)
Membership = (baseR - (testdata + ap2)) * ratioR;
return(Membership);
}
/* Use of the ABOVE function is as follows:
(double)var = Decision1(DATA_TO_TEST, d1l, d1r, apex1l, apex1r);
*/
double Decision2( double testdata, double blo,
double bhi, double ap1, double ap2 )
{
double Membership, baseL, baseR, ratioL, ratioR;
/* Exit if data not in bounds... */
if (testdata < blo) return 0;
if (testdata > bhi) return 0;
/* Data is within set boundry... */
baseL = ap1 - blo;
baseR = bhi - ap1;
ratioL = 0;
ratioR = 0;
/* Normalise test data */
if (baseL > 0) ratioL = 100 / baseL;
if (baseR > 0) ratioR = 100 / baseR;
/* TRIANGULAR */
if (testdata <= ap1) // left of apex
Membership = (testdata - baseL) * ratioL;
else
Membership = (baseR - (testdata + ap1)) * ratioR;
return(Membership);
}
/* Use of the ABOVE function is as follows:
(double)var = Decision2(DATA_TO_TEST, d2l, d2r, apex2, 0 );
*/
double Decision3( double testdata, double blo,
double bhi, double ap1, double ap2 )
{
double Membership, baseL, baseR, ratioL, ratioR;
/* Exit if data not in bounds... */
if (testdata < blo) return 0;
if (testdata > bhi) return 0;
/* Data is within set boundry... */
baseL = ap1 - blo;
baseR = bhi - ap1;
ratioL = 0;
ratioR = 0;
/* Normalise test data */
if (baseL > 0) ratioL = 100 / baseL;
if (baseR > 0) ratioR = 100 / baseR;
/* TRAPEZOIDAL */
if((testdata >= ap1) && (testdata <= ap2))
Membership = 100.0;
if(testdata <= ap1)
Membership = (testdata - baseL) * ratioL;
if(testdata > ap2)
Membership = (baseR - (testdata + ap2)) * ratioR;
return(Membership);
}
/* Use of the ABOVE function is as follows:
(double)var = Decision3(DATA_TO_TEST, d3l, d3r, apex3l, apex3r);
*/
double Decision4( double testdata, double blo,
double bhi, double ap1, double ap2 )
{
double Membership, baseL, baseR, ratioL, ratioR;
/* Exit if data not in bounds... */
if (testdata < blo) return 0;
if (testdata > bhi) return 0;
return(100.0); /* Boolean Function and data good */
}
/* Use of the ABOVE function is as follows:
(double)var = Decision4(DATA_TO_TEST, d4l, d4r, apex3l, apex3r);
*/